package cn.gok.springbootdemo05thymeleaf.contoller;

import cn.gok.springbootdemo05thymeleaf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author: chen fan
 * @since: 2022/11/16 10:28
 * @description:
 */
@Controller
public class ThymeleafController01 {


    @RequestMapping("/login.html")
    public String toLoginPage(){
        return "login";
    }


    @RequestMapping("/toThymeleafPage")
    public String toThymeleafPage(ModelMap model){
        model.addAttribute("userName","李四");
        return "thymeleaf01";
    }


    @RequestMapping("/getUsers")
    public String getUsers(ModelMap model){
        List<User> users = new ArrayList<>();
        users.add(new User(1,"zhangsan",20,"m","成都","teacher",new Date()));
        users.add(new User(2,"lisi",18,"m","成都","student",new Date()));
        users.add(new User(3,"xiaoming",21,"m","成都","student",new Date()));
        users.add(new User(4,"xiaohong",22,"w","成都", "manager",new Date()));
        model.addAttribute("users",users);
        return "users";
    }

    @RequestMapping("/getUserInfo")
    public String getUserInfo(ModelMap model){
        User user = new User(1,"zhangsan", 20, "m", "成都", "teacher", new Date());
        model.addAttribute("user",user);
        return "userinfo";
    }


    @RequestMapping("/user/deleteUser")
    public String getUserInfo(Integer id){
        System.out.println("id: " + id);
        return "success";
    }

    @RequestMapping("inline.html")
    public String inlineTest(ModelMap model){
        User user = new User(1,"zhangsan", 20, "m", "成都", "teacher", new Date());
        model.put("user",user);
        return "inline";
    }
}
